home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / arrays / vbstrapi / strdllap.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-06-24  |  18.8 KB  |  511 lines

  1. VERSION 2.00
  2. Begin Form StrDLLApp 
  3.    BackColor       =   &H00C0C0C0&
  4.    Caption         =   "VBstrAPI.DLL Demonstrator"
  5.    ClientHeight    =   5985
  6.    ClientLeft      =   45
  7.    ClientTop       =   1410
  8.    ClientWidth     =   8070
  9.    Height          =   6390
  10.    Icon            =   STRDLLAP.FRX:0000
  11.    Left            =   -15
  12.    LinkTopic       =   "Form1"
  13.    ScaleHeight     =   5985
  14.    ScaleWidth      =   8070
  15.    Top             =   1065
  16.    Width           =   8190
  17.    Begin ListBox List 
  18.       BackColor       =   &H00808000&
  19.       FontBold        =   0   'False
  20.       FontItalic      =   0   'False
  21.       FontName        =   "Fixedsys"
  22.       FontSize        =   9
  23.       FontStrikethru  =   0   'False
  24.       FontUnderline   =   0   'False
  25.       Height          =   1605
  26.       Left            =   5520
  27.       TabIndex        =   8
  28.       Tag             =   "OL"
  29.       Top             =   270
  30.       Width           =   2475
  31.    End
  32.    Begin TextBox Monitor 
  33.       BackColor       =   &H00C0C0C0&
  34.       FontBold        =   0   'False
  35.       FontItalic      =   0   'False
  36.       FontName        =   "Fixedsys"
  37.       FontSize        =   9
  38.       FontStrikethru  =   0   'False
  39.       FontUnderline   =   0   'False
  40.       Height          =   675
  41.       Left            =   150
  42.       MousePointer    =   1  'Arrow
  43.       MultiLine       =   -1  'True
  44.       ScrollBars      =   3  'Both
  45.       TabIndex        =   1
  46.       Tag             =   "OL"
  47.       Top             =   1980
  48.       Width           =   5265
  49.    End
  50.    Begin PictureBox ToolBar 
  51.       BackColor       =   &H00808000&
  52.       Height          =   1875
  53.       Left            =   0
  54.       ScaleHeight     =   1845
  55.       ScaleWidth      =   5400
  56.       TabIndex        =   0
  57.       Tag             =   "OL"
  58.       Top             =   0
  59.       Width           =   5430
  60.       Begin PictureBox Picture1 
  61.          AutoSize        =   -1  'True
  62.          BorderStyle     =   0  'None
  63.          Height          =   1800
  64.          Left            =   2970
  65.          Picture         =   STRDLLAP.FRX:0302
  66.          ScaleHeight     =   1800
  67.          ScaleWidth      =   2400
  68.          TabIndex        =   7
  69.          Top             =   30
  70.          Width           =   2400
  71.       End
  72.       Begin SSCommand biQuit 
  73.          Caption         =   "&Exit"
  74.          Font3D          =   1  'Raised w/light shading
  75.          ForeColor       =   &H00000000&
  76.          Height          =   1800
  77.          Left            =   2250
  78.          Picture         =   STRDLLAP.FRX:28FC
  79.          RoundedCorners  =   0   'False
  80.          TabIndex        =   6
  81.          Top             =   30
  82.          Width           =   705
  83.       End
  84.       Begin SSCommand biArray 
  85.          Caption         =   "&ArrayStr"
  86.          Font3D          =   1  'Raised w/light shading
  87.          Height          =   900
  88.          Left            =   1140
  89.          Picture         =   STRDLLAP.FRX:2B66
  90.          RoundedCorners  =   0   'False
  91.          TabIndex        =   5
  92.          Top             =   930
  93.          Width           =   1095
  94.       End
  95.       Begin SSCommand biCat 
  96.          Caption         =   "&CatStr"
  97.          Font3D          =   1  'Raised w/light shading
  98.          Height          =   900
  99.          Left            =   30
  100.          Picture         =   STRDLLAP.FRX:2E68
  101.          RoundedCorners  =   0   'False
  102.          TabIndex        =   4
  103.          Top             =   930
  104.          Width           =   1095
  105.       End
  106.       Begin SSCommand biCopy 
  107.          Caption         =   "C&opyFile"
  108.          Font3D          =   1  'Raised w/light shading
  109.          Height          =   885
  110.          Left            =   1140
  111.          Picture         =   STRDLLAP.FRX:316A
  112.          RoundedCorners  =   0   'False
  113.          TabIndex        =   3
  114.          Top             =   30
  115.          Width           =   1095
  116.       End
  117.       Begin SSCommand biFind 
  118.          Caption         =   "&FindString"
  119.          Font3D          =   1  'Raised w/light shading
  120.          Height          =   885
  121.          Left            =   30
  122.          Picture         =   STRDLLAP.FRX:346C
  123.          RoundedCorners  =   0   'False
  124.          TabIndex        =   2
  125.          Tag             =   "OL"
  126.          Top             =   30
  127.          Width           =   1095
  128.       End
  129.    End
  130.    Begin Label Label1 
  131.       AutoSize        =   -1  'True
  132.       BackColor       =   &H00C0C0C0&
  133.       BackStyle       =   0  'Transparent
  134.       Caption         =   "ArrayStr Demonstration List Box"
  135.       ForeColor       =   &H00800000&
  136.       Height          =   195
  137.       Left            =   5520
  138.       TabIndex        =   9
  139.       Top             =   30
  140.       Width           =   2700
  141.    End
  142. Option Explicit
  143. Sub ArrayExample ()
  144. ' Demonstration example of ArrayStr usage
  145.  Dim SHandle As Integer ' ArrayStr object handle
  146.  Dim ii      As Long    ' iterator
  147.  Dim rc      As Long    ' return code
  148.     ' create the sample array string
  149.     SHandle = CreateNewStringArray(1, 1024)
  150.     '
  151.     ' If successful, then away we go
  152.     '
  153.     If SHandle > -1 Then
  154.         
  155.         '
  156.         '  We'll start by filling the ArrayStr in Serial Mode
  157.         '
  158.         For ii = 0 To 9
  159.             ' put the string NEXT in the list
  160.             rc = PutArrayNext(SHandle, " Originally at line " & ii + 1)
  161.             If rc < 0 Then
  162.             
  163.                 MsgBox "ArrayStr Overflow! Unable to continue.", 48, "PutArrayNext Error"
  164.                 DestroyStringArray SHandle
  165.                 
  166.                 Exit Sub
  167.             
  168.             End If
  169.         Next
  170.         ' now insert a string at index #3
  171.         rc = InsertArrayStr(SHandle, 3, "!! Inserted at line 4")
  172.         
  173.         ' now delete the last string
  174.         rc = DeleteArrayStr(SHandle, 9)
  175.         ' replace the entry #7 with a message using Random Access
  176.         rc = PutArrayStr(SHandle, 7, "!! Changed line 8 with PutArrayStr")
  177.         ' place a note in the last entry that it was deleted
  178.         rc = PutArrayStr(SHandle, 9, "!! Entry deleted by DeleteArrayStr")
  179.         ' reset the current line pointer to the first entry
  180.         ArrayStrSetCLP SHandle, 0
  181.         ' using Serial Mode, fill the demonstration list box
  182.         List.Visible = False
  183.         For ii = 1 To 10
  184.             List.AddItem Format$(ii, "00") & GetArrayNext(SHandle)
  185.         Next
  186.         List.Visible = True
  187.         'rc = ArrayStrResize(SHandle, 20)
  188.         'MsgBox "(" & rc & ") " & GetArrayStr(SHandle, 1) & " [" & ArrayStrElements(SHandle) & "]"
  189.         ' ALWAYS REMEMBER TO DESTROY THE ARRAYSTR WHEN FINISHED
  190.         DestroyStringArray SHandle
  191.     Else
  192.         MsgBox "Not enough memory to create the ArrayStr Object!", 48, "ArrayStr Create Error"
  193.     End If
  194. End Sub
  195. Sub biArray_Click ()
  196. Dim CHandle As Integer
  197. Dim rc As Integer
  198.     ' This call is used to display the demonstration
  199.     ' code for the program.  Please don't look behind
  200.     ' that curtain. (The Wizard of OZ)
  201.     LocateCode "Sub Array" & "Example", "End Sub" & Chr$(13)
  202.     ArrayExample
  203.     CHandle = CreateNewCatString(4096)
  204.     rc = CatStrAddLine(CHandle, "Examine the Code in the Code Window below.")
  205.     rc = CatStrAddLine(CHandle, "")
  206.     rc = CatStrAddLine(CHandle, "Then examine the contents of the ListBox.")
  207.     rc = CatStrAddLine(CHandle, "")
  208.     rc = CatStrAddLine(CHandle, "The ListBox demonstrates the result of the example code.")
  209.     HintMsg CHandle, "ArrayStr Example Code"
  210.     DestroyCatString CHandle
  211. End Sub
  212. Sub biCat_Click ()
  213.  Dim rc      As Integer
  214.  Dim CHandle As Integer
  215.     ' This call is used to display the demonstration
  216.     ' code for the program.  Please don't look behind
  217.     ' that curtain. (The Wizard of OZ)
  218.     On Error Resume Next
  219.     List.Clear
  220.     Kill "CatStr.Txt"
  221.     CHandle = CreateNewCatString(4096)
  222.     Monitor = ""
  223.     LocateCode "Sub Cat" & "Example", "End Sub" & Chr$(13)
  224.     rc = CatStrAddLine(CHandle, "What follows is a demonstration of CatStr vs VB String concatenation times for a 32k string. Only 32k strings are demonstrated because VB can not handle larger strings.")
  225.     rc = CatStrAddLine(CHandle, "")
  226.     rc = CatStrAddLine(CHandle, "When the demonstration is complete, take a look at the code below to see how it works.")
  227.     HintMsg CHandle, "CatStr Example Code"
  228.     DoEvents
  229.     CatExample
  230.     DestroyCatString CHandle
  231. End Sub
  232. ' Note: The use of CatStrAddLine in this sub is purely
  233. '       for demonstration purposes.
  234. Sub biCopy_Click ()
  235. Dim CHandle As Integer
  236. Dim rc As Integer
  237.     CopyExample
  238.     CHandle = CreateNewCatString(4096)
  239.     rc = CatStrAddLine(CHandle, "Examine the Code in the Code Window below.")
  240.     rc = CatStrAddLine(CHandle, "")
  241.     rc = CatStrAddLine(CHandle, "The Code in the Code Window demonstrates how to use the CopyFile function.")
  242.     rc = CatStrAddLine(CHandle, "")
  243.     rc = CatStrAddLine(CHandle, "The new file is located in the same directory.")
  244.     HintMsg CHandle, "CopyFile Example Code"
  245.     DestroyCatString CHandle
  246.     ' This call is used to display the demonstration
  247.     ' code for the program.  Please don't look behind
  248.     ' that curtain. (The Wizard of OZ)
  249.     LocateCode "Sub Copy" & "Example", "End Sub" & Chr$(13)
  250. End Sub
  251. ' Example use of the FindString() and CatStr Objects
  252. Sub biFind_Click ()
  253. Dim CHandle As Integer
  254. Dim rc As Integer
  255.     CHandle = CreateNewCatString(4096)
  256.     rc = CatStrAddLine(CHandle, "You are about to see a demonstration of how FindString performs against InStr.  FindString works best with large strings and medium size targets (more than 3 characters).")
  257.     rc = CatStrAddLine(CHandle, "")
  258.     rc = CatStrAddLine(CHandle, "After the dialog boxes have shown you how it performs, check out the code in the code window.")
  259.     HintMsg CHandle, "FindString vs InStr Example Code"
  260.     DoEvents
  261.     DestroyCatString CHandle
  262.     ' This call is used to display the demonstration
  263.     ' code for the program.  Please don't look behind
  264.     ' that curtain. (The Wizard of OZ)
  265.     FindExample
  266.     LocateCode "Sub Find" & "Example", "End Sub" & Chr$(13)
  267. End Sub
  268. Sub biQuit_Click ()
  269.     Unload Me
  270. End Sub
  271. ' Demonstration of how CatStr out performs VB Strings
  272. ' in concatenation speed.
  273. Sub CatExample ()
  274.  Dim CHandle As Integer ' CatStr Object Handle
  275.  Dim rc      As Integer ' return code
  276.  Dim Temp    As String  ' temp string variable for save
  277.  Dim t                  ' timer accumulator
  278.  Dim VBTime
  279.     On Error Resume Next
  280.     ' create the maximum CatStr Object
  281.     CHandle = CreateNewCatString(32768)
  282.     ' Fail if not enough memory
  283.     If CHandle < 0 Then
  284.         MsgBox "Unable to allocate 32k for CatStr!", 48, "CatStr Create Error"
  285.         Exit Sub
  286.                 
  287.     End If
  288.     ' Use 'On Error Goto' to trap when string is full
  289.     '
  290.     ' NOTE: This is the fastest way to do this and simulates
  291.     '       CatStr objects more fairly than determining the
  292.     '       length of the string with Len().
  293. ' ****************** Visual Basic String Test ************************
  294.     On Error GoTo VBStrFull
  295.     Temp$ = ""
  296.     Screen.MousePointer = 11
  297.     t = Timer
  298.     While True
  299.         Temp$ = Temp$ & "This is a sample line of text."
  300.     Wend
  301. VBStrFull:
  302.     t = Timer - t
  303.     Screen.MousePointer = 0
  304.     On Error Resume Next
  305.     VBTime = t
  306.     MsgBox "Concatenating a " & Len(Temp$) & " character Visual Basic String took " & Format$(t, "Standard") & " seconds."
  307. ' ******************** CatStr String Test ****************************
  308.     rc = 0
  309.     Screen.MousePointer = 11
  310.     t = Timer
  311.     While rc = 0
  312.         rc = CatStrAddLine(CHandle, "This is a sample line of text.")
  313.     Wend
  314.     t = Timer - t
  315.     Screen.MousePointer = 0
  316.     MsgBox "Concatenating a " & CatStrLength(CHandle) & " character CatStr took " & Format$(t, "Standard") & " seconds."
  317. ' ************************* Results **********************************
  318.     If t < VBTime Then
  319.         MsgBox "CatStr was " & Format$(VBTime / t, "Standard") & " times faster that VB!"
  320.     Else
  321.         
  322.         MsgBox "VB was " & Format$(t / VBTime, "Standard") & " times faster that CatStr!"
  323.     End If
  324.     ' ALWAYS REMEMBER TO DESTROY THE OBJECT WHEN FINISHED!
  325.     DestroyCatString CHandle
  326. End Sub
  327. Sub CenterForm (TheForm As Form, OffsetLeft As Integer, OffsetTop As Integer)
  328. Dim FLeft As Integer
  329. Dim FTop As Integer
  330.     If TheForm.WindowState <> 0 Then Exit Sub
  331.     FLeft = ((Screen.Width - TheForm.Width) \ 2) + OffsetLeft
  332.     FTop = (((Screen.Height - TheForm.Height) \ 2) + OffsetTop) * .85
  333.     If TheForm.Left = FLeft And TheForm.Top = FTop Then Exit Sub
  334.     TheForm.Move FLeft, FTop
  335. End Sub
  336. Sub CopyExample ()
  337. Dim rc As Integer
  338.     rc = CopyFile("STRDLLAP.FRM", "COPYFILE.TXT")
  339.     If rc < 0 Then MsgBox "CopyFile Function failed!", 48, "CopyFile Error #" & rc
  340. End Sub
  341. Sub FindExample ()
  342. '  Sample of FindString usage
  343. '  Many thanks to Jim Moran at Honeywell for the challenge of
  344. '  this example!
  345. '  Don't forget to check out CatStrFind() in the help file!
  346.  Dim SrcString    As String
  347.  Dim TargetString As String
  348.  Dim locn         As Long
  349.  Dim InStrTime
  350.  Dim FindStringTime
  351.  Dim ii           As Integer
  352.     SrcString = String$(32000, "A") + "BBB"
  353.     TargetString = "AAAAAAAAAAAABBB"
  354.     ' first show how InStr performs
  355.     Screen.MousePointer = 11
  356.     InStrTime = Timer
  357.     For ii = 1 To 10
  358.         locn = InStr(1, SrcString, TargetString)
  359.     Next
  360.     InStrTime = Timer - InStrTime
  361.     Screen.MousePointer = 0
  362.     MsgBox "(Found At " & locn & ") InStr took " & Format$(InStrTime / 10, "###.###0") & " seconds."
  363.     ' now show how FindString performs
  364.     Screen.MousePointer = 11
  365.     FindStringTime = Timer
  366.     For ii = 1 To 10
  367.         locn = FindString(1, SrcString, TargetString)
  368.     Next
  369.     FindStringTime = Timer - FindStringTime
  370.     Screen.MousePointer = 0
  371.     MsgBox "(Found At " & locn & ") FindString took " & Format$(FindStringTime / 10, "###.###0") & " seconds."
  372.     If FindStringTime < InStrTime Then
  373.         MsgBox "FindString was " & Format$(InStrTime / FindStringTime, "###.###0") & " times faster."
  374.     Else
  375.         
  376.         MsgBox "InStr was " & Format$(FindStringTime / InStrTime, "###.###0") & " times faster."
  377.     End If
  378. End Sub
  379. Sub Form_Load ()
  380.     On Error Resume Next
  381.     CenterForm Me, 0, 0
  382.     ChDir App.Path
  383.     Me.Top = Screen.Height * .05
  384.     Me.Height = Screen.Height * .9
  385.     Me.Left = Screen.Width * .05
  386.     Me.Width = Screen.Width * .9
  387.     Me.Show
  388. End Sub
  389. Sub Form_Paint ()
  390.     Outlines Me
  391. End Sub
  392. Sub Form_Resize ()
  393.     On Error Resume Next
  394.     Monitor.Top = ToolBar.Height + 120
  395.     Monitor.Left = 120
  396.     Monitor.Width = ScaleWidth - 240
  397.     Monitor.Height = ScaleHeight - ToolBar.Height - 240
  398.     List.Width = ScaleWidth - List.Left - 120
  399. End Sub
  400. ' This subroutine demonstrates how CatStr (and ArrayStr) Objects
  401. ' can be passed to other functions using only the handle.
  402. Sub HintMsg (CHandle As Integer, Title As String)
  403.     HintDialog.Caption = Title
  404.     HintDialog.Hint = CatStrCopy(CHandle)
  405.     HintDialog.Show 1
  406. End Sub
  407. Sub LocateCode (Head As String, Tail As String)
  408. ' This subroutine is used by the demonstration program to
  409. ' read the form file, locate the desired subroutine (beginning and
  410. ' end) and then highlight the text.
  411. ' It also serves as an example of the FindStringIC function.
  412.  Dim File    As Integer  ' file handle to load STRDLLAP.FRM
  413.  Dim Buf     As String   ' line buffer
  414.  Dim CHandle As Integer  ' CatStr Object handle
  415.  Dim rc      As Integer  ' return code
  416.  Dim Looping As Integer  ' looping switch while reading file
  417.  Dim locn    As Long     ' location pointer for FindStringIC
  418.  Dim length  As Long     ' calculated length of located text
  419.     ' locate a free file handle
  420.     MousePointer = 11
  421.     List.Clear
  422.     Monitor.Visible = False
  423.     Monitor = ""
  424.     File = FreeFile
  425.     ' create a new CatStr object
  426.     CHandle = CreateNewCatString(32768)
  427.     ' open and read the file
  428.     Open "STRDLLAPP.FRM" For Input As #File
  429.     Looping = True
  430.     While Not EOF(File) And Looping
  431.         Line Input #File, Buf
  432.         ' use the CatStr object to buffer the
  433.         ' lines read from the file
  434.         rc = CatStrAddLine(CHandle, Buf)
  435.         '
  436.         ' stop if no more room in the buffer
  437.         '
  438.         If rc < 0 Then ' can't read any more
  439.             Looping = False
  440.         End If
  441.     Wend
  442.     Close #File
  443.     '
  444.     ' search for the subroutine declaration
  445.     '
  446.     locn = CatStrFind(CHandle, 1, Head)
  447.     '
  448.     ' As long as you haven't fiddled with the code
  449.     ' this should work
  450.     '
  451.     If locn > 0 Then
  452.         length = CatStrFind(CHandle, locn, Tail) - locn + Len(Tail) - 1
  453.         Monitor = CatStrMid$(CHandle, locn, length)
  454.     Else
  455.         MsgBox "This example requires an un-modified version of STRDLLAPP.FRM", 48, "Demo Error"
  456.     End If
  457.     '
  458.     ' ALWAYS REMEMBER TO DESTROY THE OBJECT WHEN FINISHED
  459.     '
  460.     DestroyCatString CHandle
  461.     MousePointer = 0
  462.     Monitor.Visible = True
  463.     Monitor.SetFocus
  464. End Sub
  465. Sub Monitor_KeyPress (KeyAscii As Integer)
  466.     KeyAscii = 0
  467. End Sub
  468. Sub Outlines (FormName As Form)
  469. Dim drkgray     As Long
  470. Dim fullwhite   As Long
  471. Dim i           As Integer
  472. Dim ctop        As Integer
  473. Dim cleft       As Integer
  474. Dim cright      As Integer
  475. Dim cbottom     As Integer
  476. Dim Offset      As Integer
  477.     On Error Resume Next
  478.     Dim cName As Control
  479.     Offset = 0
  480.     FormName.Cls
  481.     drkgray = RGB(128, 128, 128)
  482.     fullwhite = RGB(255, 255, 255)
  483.     For i = 0 To (FormName.Controls.Count - 1)
  484.         
  485.         Set cName = FormName.Controls(i)
  486.         If TypeOf cName Is Menu Then
  487.             GoTo SkipThisControl
  488.             
  489.         End If
  490.             
  491.         
  492.         If (UCase(cName.Tag) = "OL") Then
  493.                 
  494.             ctop = cName.Top - Screen.TwipsPerPixelY
  495.             cleft = cName.Left - Screen.TwipsPerPixelX
  496.             cright = cName.Left + cName.Width + (Screen.TwipsPerPixelX * Offset)
  497.             cbottom = cName.Top + cName.Height + (Screen.TwipsPerPixelY * Offset)
  498.             
  499.             FormName.Line (cleft, ctop)-(cright, ctop), drkgray
  500.             FormName.Line (cleft, ctop)-(cleft, cbottom), drkgray
  501.             FormName.Line (cleft, cbottom)-(cright, cbottom), fullwhite
  502.             FormName.Line (cright, ctop)-(cright, cbottom), fullwhite
  503.         
  504.         End If
  505. SkipThisControl:
  506.     Next i
  507. End Sub
  508. Sub ToolBar_Click ()
  509.     Outlines Me
  510. End Sub
  511.